package rpc

import (
	"context"
	"errors"
	"github.com/smallnest/rpcx/client"
	"github.com/smallnest/rpcx/protocol"
)

var (
	//ErrEmptyClient means empty client call
	ErrEmptyClient = errors.New("empty client")
)

var _ client.XClient = (*emptyCreator)(nil)

//CreateEmptyCreator return a empty creator, it create client do noting
func CreateEmptyCreator() func(string) (client.XClient, error) {
	return func(name string) (c client.XClient, err error) {
		return (*emptyCreator)(nil), nil
	}
}

//emptyCreator do noting but return a ErrEmptyClient
type emptyCreator struct{}

func (*emptyCreator) SetPlugins(plugins client.PluginContainer)     {}
func (*emptyCreator) SetSelector(s client.Selector)                 {}
func (*emptyCreator) ConfigGeoSelector(latitude, longitude float64) {}
func (*emptyCreator) Auth(auth string)                              {}

func (*emptyCreator) Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (*client.Call, error) {
	return nil, ErrEmptyClient
}
func (*emptyCreator) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
	return ErrEmptyClient
}
func (*emptyCreator) Broadcast(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
	return ErrEmptyClient
}
func (*emptyCreator) Fork(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
	return ErrEmptyClient
}
func (*emptyCreator) SendRaw(ctx context.Context, r *protocol.Message) (map[string]string, []byte, error) {
	return nil, nil, ErrEmptyClient
}
func (*emptyCreator) Close() error {
	return nil
}
